package com.example.fasttalk.setting;

import com.example.fasttalk.model.intfc.FastTalkSettingData;
import com.intellij.openapi.options.Configurable;
import javax.swing.JComponent;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;

/**
 * @author SundayLi
 * @date 2023/2/24 18:38
 */
public class FastTalkSettingsConfigurable implements Configurable {
  private FastTalkSettingsComponent settingsComponent;

  @Nls(capitalization = Nls.Capitalization.Title)
  @Override
  public String getDisplayName() {
    return "fast talk setting";
  }

  @Override
  public JComponent getPreferredFocusedComponent() {
    return settingsComponent.getPreferredFocusedComponent();
  }

  @Nullable
  @Override
  public JComponent createComponent() {
    settingsComponent = new FastTalkSettingsComponent();
    return settingsComponent.getPanel();
  }

  @Override
  public boolean isModified() {
    FastTalkSettings settings = FastTalkSettings.getInstance();
    return !FastTalkSettingData.equals(settings.getState(), settingsComponent);
  }

  @Override
  public void apply() {
    FastTalkSettings settings = FastTalkSettings.getInstance();
    FastTalkSettingData.copyTo(settingsComponent, settings.getState());
  }

  @Override
  public void reset() {
    FastTalkSettings settings = FastTalkSettings.getInstance();
    FastTalkSettingData.copyTo(settings.getState(), settingsComponent);
  }

  @Override
  public void disposeUIResources() {
    settingsComponent = null;
  }
}
